﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Wpf_Test1
{
    internal class DengluCommond : ICommand
    {
        //命令是否执行
        readonly Func<bool> canExecute;

        //命令执行的方法
        readonly Action execute;

        //实例化对象传入参数
        public DengluCommond(Action action, Func<bool> CanExecute)
        {
            canExecute = CanExecute;
            execute = action;
        }
        public bool CanExecute(object parameter)
        {
            if (canExecute != null)
            {
                return true;
            }
            return canExecute();
        }

        public void Execute(object parameter)
        {
            execute();
        }

        public event EventHandler CanExecuteChanged
        {
            add
            {
                if (canExecute != null)
                {
                    CommandManager.RequerySuggested += value;
                }
            }
            remove
            {
                CommandManager.RequerySuggested += value;
            }
        }
    }
}
